﻿// ***********************************************************************
// Project          : Micua
// Assembly         : Micua.Core
// Author           : Administrator
// Created          : 2013-12-29 3:12 AM
// 
// Last Modified By : Administrator
// Last Modified On : 2013-12-29 3:12 AM
// ***********************************************************************
// <copyright file="Entity.cs" company="Wedn.Net">
//     Copyright (c) Wedn.Net. All rights reserved.
// </copyright>
// <summary></summary>
// ***********************************************************************

using System.IO;
using System.Reflection;
using System.Runtime.Serialization.Formatters.Binary;
using Micua.Utility;

namespace Micua.Extension
{
    /// <summary>
    /// 实体拓展方法
    /// </summary>
    public static class Entity
    {
        ///// <summary>
        ///// 深拷贝当前对象
        ///// </summary>
        ///// <typeparam name="T">当前对象类型</typeparam>
        ///// <param name="entity">当前对象</param>
        ///// <returns>当前对象副本</returns>
        //public static T Clone<T>(this T entity) where T : class
        //{
        //    #region 二进制序列化
        //    //using (var ms = new MemoryStream())
        //    //{
        //    //    var bf = new BinaryFormatter();
        //    //    bf.Serialize(ms, entity);
        //    //    ms.Position = 0;
        //    //    return (T)bf.Deserialize(ms);
        //    //}
        //    #endregion

        //    #region Json序列化

        //    //var json = JsonHelper.Serialize(entity);
        //    //var newEntity = JsonHelper.Deserialize<T>(json);
        //    //return newEntity;

        //    #endregion
        //    //T clone = ctx.CreateObject<T>();
        //    //PropertyInfo[] pis = entity.GetType().GetProperties();

        //    //foreach (PropertyInfo pi in pis)
        //    //{
        //    //    EdmScalarPropertyAttribute[] attrs = (EdmScalarPropertyAttribute[])pi.GetCustomAttributes(typeof(EdmScalarPropertyAttribute), false);

        //    //    foreach (EdmScalarPropertyAttribute attr in attrs)
        //    //    {
        //    //        if (!copyKeys && attr.EntityKeyProperty)
        //    //            continue;

        //    //        pi.SetValue(clone, pi.GetValue(entity, null), null);
        //    //    }
        //    //}

        //    //return clone;
        //    return null;
        //}  

    }
}